/*******************************************************************************
  Name: fenv.h
  Copyright: Kieran Foot 2009
  Author: Kieran Foot
  Date: 12/06/09 15:25
  Description: Floating point environment
*******************************************************************************/

#include <_ansi.h>

#ifndef __FENV_H__
#define __FENV_H__

_BEGIN_STD_C

enum {
    FE_INVALID = 0x01,
#define FE_INVALID	FE_INVALID
    __FE_DENORM = 0x02,
    FE_DIVBYZERO = 0x04,
#define FE_DIVBYZERO	FE_DIVBYZERO
    FE_OVERFLOW = 0x08,
#define FE_OVERFLOW	FE_OVERFLOW
    FE_UNDERFLOW = 0x10,
#define FE_UNDERFLOW	FE_UNDERFLOW
    FE_INEXACT = 0x20
#define FE_INEXACT	FE_INEXACT
};
  
#define FE_ALL_EXCEPT \
	(FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)

enum {
    FE_TONEAREST = 0,
#define FE_TONEAREST	FE_TONEAREST
    FE_DOWNWARD = 0x400,
#define FE_DOWNWARD	FE_DOWNWARD
    FE_UPWARD = 0x800,
#define FE_UPWARD	FE_UPWARD
    FE_TOWARDZERO = 0xc00
#define FE_TOWARDZERO	FE_TOWARDZERO
};
 
// Type representing exception flags.
typedef unsigned short int fexcept_t;

typedef struct {
    unsigned int unused;
} fenv_t;

// Default floating point state
extern const fenv_t * FE_DFL_ENV;

// Floating Point Environment Functions
int feclearexcept(int excepts);
int fegetenv(fenv_t *penv);
int fegetexceptflag(fexcept_t *pflags, int excepts);
int fegetround(void);
int feholdexcept(fenv_t *penv);
int feraiseexcept(fenv_t *penv);
int fesetenv(const fenv_t *penv);
int fesetexceptflag(const fexcept_t *pflags, int excepts);
int fesetround(int round);
int fetestexcept(int excepts);
int feupdateenv(const fenv_t *penv);

_END_STD_C

#endif
